function CustomerInfo_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div class="customerinfo border-bottom"><div class="customername cusname">加载中...</div><div class="customermore"><div class="customerstate cstate"></div><div class="customertime clastconndate"></div></div></div>');
	
	buffer.append('<div class="customertab"><div class="cusline1 select ui-border-r" val="1">销售记录</div><div class="cusline2" val="2">客户详细</div><div class="cusline3" val="3">联系人</div><div class="cusline4" val="4">订单</div><div class="cusline5" val="5">合同</div></div>');
	buffer.append('<div class="customerpanel border-top">');
	buffer.append('<div class="panels" id="panel10" pageindex="0" style="width:'+swidth+'px;height:'+(sheight-141)+'px; position:absolute;"><div id="wrapper10" ><div id="scroller"><div id="reflash10" style="margin-top:-5px;"></div><div id="info10"></div><div id="loading10"><img src="img/loading.gif"/></div></div></div><div id="addrecord" class="addrecord"><img src="img/add.png"></div></div>');
	buffer.append('<div class="panels hidden" id="panel11" pageindex="0" style="width:'+swidth+'px;height:'+(sheight-141)+'px; position:absolute; overflow-y:auto;">');
	buffer.append('<div class="line"><div class="name">客户名称</div><div class="value cusname"></div></div>');
	buffer.append('<div class="line"><div class="name">负&nbsp; 责&nbsp; 人</div><div class="value ccontact"></div></div>');
	buffer.append('<div class="line"><div class="name">客户地址</div><div class="value caddress"></div></div>');
	buffer.append('<div class="line"><div class="name">公司网址</div><div class="value cwebsite"></div></div>');
	buffer.append('<div class="line"><div class="name">客户状态</div><div class="value ccstate"></div></div>');
	buffer.append('<div class="line"><div class="name">联合跟进人</div><div class="value cfollowuser"></div></div>');
	buffer.append('<div class="line"><div class="name">创建时间</div><div class="value ccreatedate"></div></div>');
	buffer.append('<div class="line"><div class="name">最后修改时间</div><div class="value clasteditdate"></div></div>');
	buffer.append('<div id="expand_tags"></div>');
	buffer.append('<div class="line"><div class="name">备注</div><div class="value cbak"></div></div>');
	buffer.append('</div>');
	buffer.append('<div class="panels hidden" id="panel12" pageindex="0" style="width:'+swidth+'px;height:'+(sheight-141)+'px; position:absolute; overflow-y:auto;"><div id="info12"><div id="loading12"><img src="img/loading.gif"/></div></div><div id="addcontact" class="addrecord"><img src="img/add.png"></div></div>');
	buffer.append('<div class="panels hidden" id="panel13" pageindex="0" style="width:'+swidth+'px;height:'+(sheight-141)+'px; position:absolute; overflow-y:auto;"><div id="info13"><div id="loading13"><img src="img/loading.gif"/></div></div></div>');
	buffer.append('<div class="panels hidden" id="panel14" pageindex="0" style="width:'+swidth+'px;height:'+(sheight-141)+'px; position:absolute; overflow-y:auto;"><div id="info14"><div id="loading14"><img src="img/loading.gif"/></div></div></div>');
	buffer.append('</div>');
	return buffer.toString();
};

function CustomerInfo_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		try{
		info.Context=decodeURI(info.Context);
		}catch(e){}
		buffer.append('<div class="customerdetail border-bottom" id="'+info.ID+'"><div class="top"><div class="headimg"><img src="'+info.HeadImg+'"/></div><div class="name"><div class="realname">'+info.RealName+'</div><div class="source">'+info.Date+' '+info.Time+' &nbsp;&nbsp;&nbsp; 来自：'+info.Version+'</div></div></div>');
		buffer.append('<div class="action">标签：'+info.Action);
		if(info.NextCallTime!="2015-01-01 00:00:00"){
			buffer.append('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;下次回访时间：'+info.NextCallTime.ToTime());
		}
		buffer.append('</div><div class="context">'+info.Context+'</div>');
		buffer.append('<div class="imgs">');
		$(info.Imgs).each(function(k,img)
		{
			//var right=k%3==2?0:10;
			buffer.append('<figure style="width:'+(swidth-100)/3+'px; heigth:'+(swidth-100)/3+'px; margin:0px; padding:0px; margin-right:5px; float:left; display:block; " itemscope itemtype="http://schema.org/ImageObject"><a src="'+img.Img1000+'" itemprop="contentUrl" data-size="'+img.Width+'x'+img.Height+'"><img src="' + img.Img200 + '" width="'+(swidth-100)/3+'" height="'+(swidth-100)/3+'" itemprop="thumbnail" alt="Image description"/></a></figure>');
		});
		buffer.append('</div>');
		buffer.append('<div class="bottom"><div class="delete"><img src="img/delete.png" height="12"/></div></div></div>');
	});
	return buffer.toString();
};
function SaleRecord_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find" class="finds2"><div class="searchinput ui-border-radius"><input id="keyword" class="bordersolid" type="text" value="" onblur="Show_Search()" onkeyup="SaleRecord_Search();"/><div id="searchicon" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons" class="searchicons"><img src="img/jings.jpg"/></div></div></div>');
	buffer.append('<div class="horizen border-bottom"></div>');
	return buffer.toString();
};
function SaleRecord_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		try{
		info.Context=decodeURI(info.Context);
		}catch(e){}
		buffer.append('<div class="customerdetail border-bottom" id="'+info.ID+'"><div class="top"><div class="headimg"><img src="'+info.HeadImg+'"/></div><div class="name"><div class="realname">'+info.RealName+'</div><div class="customername">'+info.CustomerName+'</div><div class="source">'+info.Date+' '+info.Time+' &nbsp;&nbsp;&nbsp; 来自：'+info.Version+'</div></div></div>');
		buffer.append('<div class="action">标签：'+info.Action);
		if(info.NextCallTime!="2015-01-01 00:00:00"){
			buffer.append('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;下次回访时间：'+info.NextCallTime.ToTime());
		}
		buffer.append('</div><div class="context">'+info.Context+'</div>');
		buffer.append('<div class="imgs">');
		$(info.Imgs).each(function(k,img)
		{
			//var right=k%3==2?0:10;
			buffer.append('<figure style="width:'+(swidth-100)/3+'px; heigth:'+(swidth-100)/3+'px; margin:0px; padding:0px; margin-right:5px; float:left; display:block; " itemscope itemtype="http://schema.org/ImageObject"><a src="'+img.Img1000+'" itemprop="contentUrl" data-size="'+img.Width+'x'+img.Height+'"><img src="' + img.Img200 + '" width="'+(swidth-100)/3+'" height="'+(swidth-100)/3+'" itemprop="thumbnail" alt="Image description"/></a></figure>');
		});
		buffer.append('</div>');
		buffer.append('<div class="bottom"><div class="delete">删除</div></div></div>');
	});
	return buffer.toString();
};
function Receive_SaleRecord(pageindex,mbegindate,menddate)
{
	var begindate=RUndefined($("#begindate_search").val());
	var enddate=RUndefined($("#enddate_search").val());
	if(mbegindate){begindate=mbegindate;}
	if(menddate){enddate=menddate;}
	var data = {};
			data.act = "Find_SaleRecord";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword").val();
		    data.timer = begindate + "～" + enddate;
		    data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist1").html(SaleRecord_Data(json.data.list));
					}else{
						$("#contentlist1").append(SaleRecord_Data(json.data.list));
					}
					setTimeout(function(){
						myScroll1.refresh();
						initPhotoSwipeFromDOM('.customerdetail');
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.list.length!=data.pagesize)
					{
						$("#loading1").html("");
					}else{
						$("#loading1").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist1").html("");
						$("#loading1").html("主人，没有找到您需要的数据");
					}else
					{
						$("#loading1").html("没有更多了");
					}
				}
         		pageindex = parseInt($("#divmsg1").attr("pageindex"))+1;
         		$("#divmsg1").attr("pageindex",pageindex);
         		
         		mui(".customerdetail").off("tap",".delete");
         		mui(".customerdetail").on("tap",".delete",function() {
         			var salerecordlist=$(this).parent().parent();
         			var data = {};
						    data.id = salerecordlist.attr("id");
						    data.act = "Delete_SaleRecord";
						    data.source = source; 
						    data.version = version;
						    data.userid=userid;
							data.comid=comid;
							data.sign=GetSign(data.act);
						    plus.nativeUI.confirm("确定要删除该销售记录吗？", function(event){
							if(event.index==1)
							{ 
								mui.getJSON(crm_domain, data, function(json) {
									if (json.state) {
										salerecordlist.hide(500);
							            plus.nativeUI.toast("删除成功");
							            FindCrmReport();
							        } else {
							            plus.nativeUI.toast("删除失败");
							        }
								});
							}
							},"提示", ["取消","确认"]); 
         		});
			});
};

function SaleRecord_Search(){
	pageindex=1;
	$("#divmsg1").attr("pageindex","0");
	var date=new Date();
	var year=date.getFullYear();
	var month=date.getMonth()+1;
	var begindate=year+"-"+month+"-01";
	var enddate=year+"-"+month+"-"+DayNumOfMonth(year,month);
	Receive_SaleRecord(1,begindate,enddate);
};
function OrderInfo_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="orderdetail border-bottom" id="'+info.ID+'"><div class="ordernum"><font>单号&nbsp;&nbsp;</font>'+info.Num+'</div><div class="orderstate"><font>订单状态&nbsp;&nbsp;</font>'+info.StateText+'</div><div class="orderpaytype"><font>付款方式&nbsp;&nbsp;</font>'+info.PayTypeText+'</div><div class="ordermoney"><font>订单金额&nbsp;&nbsp;</font>'+info.AllMoney.toFixed(2)+'</div><div class="orderrealname"><font>创&nbsp; 建&nbsp; 人&nbsp;&nbsp;</font>'+info.RealName+'</div><div class="ordercreatedate"><font>创建时间&nbsp;&nbsp;</font>'+info.CreateDate.ToTime()+'</div><div class="orderaddress"><font>收货地址&nbsp;&nbsp;</font>'+info.Address+'</div></div>');
	});
	return buffer.toString();
};

function ContactInfo_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		var mobile=info.Mobile;
		if(mobile.Trim()==""){mobile=info.Phone;}
		if(mobile.Trim()==""){mobile="暂无电话";}
		buffer.append('<div class="contactdetail border-bottom" id="'+info.ID+'"><div class="name">'+info.Name+'</div><div class="mobile lightblue">'+mobile+'</div><div class="duty">'+info.Duty+'</div></div>');
	});
	return buffer.toString();
};
function ContractInfo_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="contractdetail border-bottom" id="'+info.ID+'"><div class="num"><font>合同编号&nbsp;&nbsp;</font>'+info.Num+'</div><div class="headusername"><font>负&nbsp; 责&nbsp; 人&nbsp;&nbsp;</font>'+info.HeadUserName+'</div><div class="dismoney"><font>合同金额&nbsp;&nbsp;</font>'+info.DisMoney.toFixed(2)+'</div><div class="percent"><font>合同折扣&nbsp;&nbsp;</font>'+info.Percent+'%</div><div class="backmoney"><font>回款金额&nbsp;&nbsp;</font>'+info.BackMoney.toFixed(2)+'</div><div class="signdate"><font>签约日期&nbsp;&nbsp;</font>'+info.SignDate.ToTime()+'</div><div class="enddate"><font>到期日期&nbsp;&nbsp;</font>'+info.EndDate.ToTime()+'</div></div>');
	});
	return buffer.toString();
};

function CustomerInfo_Search(){
	pageindex = 1;
    $("#panel10").attr("pageindex",0);
	Receive_CustomerInfo(1);
}

function Receive_CustomerInfo(pageindex)
{
	var data = {};
			data.act = "Find_SaleRecord_ByCustomerID";
			data.customerid = obj.attr("id");
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE10;
			data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					if(pageindex==1)
					{
						$("#info10").html(CustomerInfo_Data(json.data.list));
					}else{
						$("#info10").append(CustomerInfo_Data(json.data.list));
					}
					if(json.data.list.length!=data.pagesize)
					{
						$("#loading10").html("");
					}else{
						$("#loading10").html('<img src="img/loading.gif"/>');
					}
					setTimeout(function(){
						//Init_NotePad();
						myScroll10.refresh();
						initPhotoSwipeFromDOM('.customerdetail');
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					
				}else
				{
					if(pageindex==1)
					{
						$("#loading10").html("主人，还没有相关销售记录哦");
					}else
					{
						$("#loading10").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#panel10").attr("pageindex"))+1;
         		$("#panel10").attr("pageindex",pageindex);
         		
         		mui(".customerdetail").off("tap",".delete");
         		mui(".customerdetail").on("tap",".delete",function() {
         			var salerecordlist=$(this).parent().parent();
         			var data = {};
						    data.id = salerecordlist.attr("id");
						    data.act = "Delete_SaleRecord";
						    data.source = source; 
						    data.version = version;
						    data.userid=userid;
							data.comid=comid;
							data.sign=GetSign(data.act);
						    plus.nativeUI.confirm("确定要删除该销售记录吗？", function(event){
							if(event.index==1)
							{ 
								mui.getJSON(crm_domain, data, function(json) {
									if (json.state) {
										salerecordlist.hide(500);
							            plus.nativeUI.toast("删除成功");
							            FindCrmReport();
							        } else {
							            plus.nativeUI.toast("删除失败");
							        }
								});
							}
							},"提示", ["取消","确认"]); 
         		});
			});
};

var myScroll10;

function Receive_OrderInfo()
{
	var data = {};
			data.act = "Find_POrder_ByCustomerID";
			data.customerid = obj.attr("id");
			data.userid=userid;
			data.comid=comid;
			data.pageindex=1;
			data.source=source;
			data.pagesize=PAGE_SIZE10;
			data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					$("#info13").html(OrderInfo_Data(json.data.list));
				}else
				{
					$("#loading13").html("主人，没有找到您需要的数据");
				}
			});
};

function Receive_ContractInfo()
{
	var data = {};
			data.act = "Find_Contract_ByCustomerID";
			data.customerid = obj.attr("id");
			data.userid=userid;
			data.comid=comid;
			data.pageindex=1;
			data.source=source;
			data.pagesize=PAGE_SIZE10;
			data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					$("#info14").html(ContractInfo_Data(json.data.list));
				}else
				{
					$("#loading14").html("主人，没有找到您需要的数据");
				}
			});
};

function Receive_ContactInfo()
{
	var data = {};
			data.act = "Find_Contact_ByCustomerID";
			data.customerid = obj.attr("id");
			data.userid=userid;
			data.comid=comid;
			data.source=source;
			data.pagesize=PAGE_SIZE10;
			data.sign=GetSign(data.act);
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					$("#info12").html(ContactInfo_Data(json.data.list));
					mui("#info12").on("tap",".contactdetail",function(){
						var phone=$(this).find(".mobile").html();
						var name=$(this).find(".name").html();
						var html='<div class="contactdialog"><div id="sms" class="addcontact border-bottom">发短信</div><div id="phone" class="addcontact border-bottom">打电话</div><div id="savephone" class="addcontact">保存至本地通讯录</div></div>';
						OpenMeng3(html,sheight/2);
						get("sms").addEventListener("tap",function(){
							window.location.href="sms:"+phone;
						});
						get("phone").addEventListener("tap",function(){
							window.location.href="tel:"+phone;
						});
						get("savephone").addEventListener("tap",function(){
							plus.contacts.getAddressBook( plus.contacts.ADDRESSBOOK_PHONE, function( addressbook ) {
								// 可通过addressbook进行通讯录操作
								var contact = addressbook.create();
									contact.name = {givenName:name};
									contact.phoneNumbers = [{type:"mobile",value:phone,preferred:true}];
									contact.save( function () {
										CloseMeng3();
										plus.nativeUI.toast("已成功保存至通讯录");
									}, function ( e ) {
										plus.nativeUI.toast("保存失败");
									} );
								}, function ( e ) {
									plus.nativeUI.toast("保存失败");
							});
	
						});
					});
				}else
				{
					$("#loading12").html("主人，没有找到您需要的数据");
				}
			});
};
function Init_CustomerInfo()
{
		//销售记录
		myScroll10=AtScroll(10,"panel10",function(pageindex){
			Receive_CustomerInfo(pageindex);
		});
		Receive_CustomerInfo(1);
		
		mui(".customertab").on("tap","div",function(){
			
			$("#panel1"+ (parseInt($(this).attr("val"))-1)).removeClass("hidden").siblings().addClass("hidden");
			var tabindex=$(this).attr("val");
			$(".customertab .cusline1").attr("class","cusline1");
			$(".customertab .cusline2").attr("class","cusline2");
			$(".customertab .cusline3").attr("class","cusline3");
			$(".customertab .cusline4").attr("class","cusline4");
			$(".customertab .cusline5").attr("class","cusline5");
			if(tabindex=="1")
			{
				myScroll10.refresh();
				$(".customertab .cusline1").attr("class","cusline1 ui-border-r");
			}else if(tabindex=="2")
			{
				$(".customertab .cusline2").attr("class","cusline2 ui-border-l").next().attr("class","cusline3 ui-border-l");
			}
			else if(tabindex=="3")
			{
				$(".customertab .cusline3").attr("class","cusline3 ui-border-l").next().attr("class","cusline4  ui-border-l");
			}
			else if(tabindex=="4")
			{
				$(".customertab .cusline4").attr("class","cusline4  ui-border-l").next().attr("class","cusline5 ui-border-l");
				//myScroll13.refresh();
			}
			else if(tabindex=="5")
			{
				$(".customertab .cusline5").attr("class","cusline5 ui-border-l");
			}
			$(this).addClass("select");
		});
		
		get("addrecord").addEventListener("tap",function(){
			OpenWindow(3,"添加销售记录","保存",function(){
				SaleRecord_Submit();
			});
			setTimeout(function(){
			$("#contentlist3").html(SaleRecordAdd_Code());
			Init_SaleRecordAdd();
			},10);
		});
		get("addcontact").addEventListener("tap",function(){
			var html='<div class="contactdialog"><div id="insertcontact" class="addcontact border-bottom">添加新联系人</div><div id="selectcontact" class="addcontact">关联已有联系人</div></div>';
			OpenMeng3(html,sheight/2);
			get("insertcontact").addEventListener("tap",function(){
				OpenWindow(4,"联系人","保存",function(){
										Save_Contact();
									});
									$("#contentlist4").html(ContactAdd_Code(0));
									Init_ContactAdd(obj.attr("id"));
				CloseMeng3();
			});
			get("selectcontact").addEventListener("tap",function(){
				myScroll3 = OpenScroll2(4,"选择联系人","",function(pageindex){
										Receive_ContactSelect(pageindex);
								},function(){
									
								},ContactSelect_Code(),70);
								//$("#contentlist2").append(Publish_Code());
								Receive_ContactSelect(1);
								get("find2").addEventListener("tap",function(){
				      				$("#searchicon2").hide();
	      							$("#searchicons2").show();
	      							$("#keyword2").attr("placeholder","联系人姓名(支持拼音)，手机");
			    					if($("keyword2").val()!="")
			    					{
			    						//WorkMate_Search();
			    					}
				      			});
				CloseMeng3();
			});
		});
		//客户详情
		Init_CustomerDetail();
		//联系人
		Receive_ContactInfo();
		//订单
		Receive_OrderInfo();
		//合同
		Receive_ContractInfo();
		
};


function Init_CustomerDetail(){
	
	var data = {};
    data.act = "One_Customer";
    data.id = obj.attr("id");
    data.userid=userid;
	data.comid=comid;
	data.source=source;
	data.pagesize=PAGE_SIZE10;
	data.sign=GetSign(data.act);
    mui.getJSON(crm_domain, data, function(json) {
    	var customer = json.data.customer;
    	var str="";
    	var isselect="";
    	$.each(json.data.state, function(i,info) {
    		if(customer.State==info.Name)
    		{
    			isselect="selected='selected'";
    		}else
    		{
    			isselect="";
    		}
    		str+='<option value="'+info.Name+'" '+isselect+'>'+info.Name+'</option>';
    	});
        
        var tags = json.data.tags;
        $(".cusname").html(customer.Name);
        $(".ccontact").html(customer.HeadUserName);
        $(".caddress").html(customer.Address.ToString());
        $(".cwebsite").html(customer.WebSite.ToString());
        $(".cstate").html('<select id="customerstate" onchange="Set_CustomerState(this)">'+str+'</select>');
        $(".ccstate").html(customer.State);
        $(".ccreatedate").html(customer.CreateDate);
        $(".clasteditdate").html(customer.LastEditDate);
        $(".cbak").html(customer.Bak.ToString());
        $(".cfollowuser").html(FollowUser_Templete(customer.FollowUserList));
        $(".clastconndate").html(customer.LastConnDate.ToTime());
        //初始化拓展字段
        Init_ExpandTags(tags);
        
        mui(".cfollowuser").on("tap",".head",function(){
        	FollowUser_Delete(this);
        });
        
        get("addfollowuser").addEventListener("tap",function(){
        	obj10=$(this);
			OpenWindow(3,"选择联合跟进人","确定",function(){
					var str1="",str2="",str3="",headimg="";
					touserid="";todepartid="";tocomid="";
	      			var count=0;
	      			mui.each(mui("#userlist input"),function(i,info){
	      				if(info.checked)
	      				{
	      					count++;
	      					touserid += info.value+",";
	      					headimg=$(info).parent().parent().find(".headimg img").attr("src");
	      				}
	      			});
	      			if(touserid.TrimEnd(",").split(",").length>1)
					{
						plus.nativeUI.toast("请选择1个联合跟进人");
						return;
					}
					data = {};
		            data.id = obj.attr("id");
		            data.followuser = touserid.TrimEnd(",");
		            data.handle = "add";
		            data.userid=userid;
					data.comid=comid;
					data.source=source;
		            data.act = "FollowUser_Customer";
		            data.sign=GetSign(data.act);
		            mui.getJSON(crm_domain, data, function (json) {
		                if (json.state) {
		                    $(".cfollowuser .head[uid='" + data.followuser + "']").remove();
		                    $('<div class="head" onclick="FollowUser_Customer(this)" handle="delete" uid="' + data.followuser + '"><img src="'+headimg+'"/></div>').insertBefore($("#addfollowuser").parent());
		                    plus.nativeUI.toast(json.msg);
		                } else {
		                    plus.nativeUI.toast(json.msg);
		                }
		            });
	      			CloseWindow();
			});
			
			$("#contentlist3").html(CheckMate_Data());
			data = {};
			data.act = "DepartAndUser_Data";
			data.userid=userid;
			data.comid=comid;
			data.source=source;
			data.sign=GetSign(data.act);
			
			mui.getJSON(admin_domain, data, function(json) {
				Bind_CheckMate(json.data.user,json.data.depart);
				Init_CheckMate();
			});
			if($(this).attr("show")=="1")
	      	{
	      		$(".selectbar").hide();
	      	}else
	      	{
				$(".selectbar").show();  				
	      	}
	        });
    });
};

function Set_CustomerState(o){
	var data = {};
    data.id = obj.attr("id");
    data.userid=userid;
	data.comid=comid;
	data.source=source;
    data.state = $(o).val();
    data.act = "Customer_State";
    data.sign=GetSign(data.act);
    mui.getJSON(crm_domain, data, function (json) {
        plus.nativeUI.toast(json.msg);
        if (json.state) {
            $(".ccstate").html(data.state);
            obj.find(".state").html(data.state);
        }
    });
};

//联合跟进人模板
function FollowUser_Templete(data) {
    var str = "";
    $.each(data, function (i, info) {
        str += '<div class="head" title="' + info.RealName + '" handle="delete" uid="' + info.ID + '" ><img src="' + info.HeadImg + '"/></div>';
    });
    str += '<div class="add"><a id="addfollowuser" show="1" touserid="" todepartid="" tocomid="" handle="add"><img src="img/add2.png"/></a></div>';
    return str;
};

//初始化拓展字段
function Init_ExpandTags(tags) {
    var str="";
    $.each(tags,function(i,info){
        str+='<div class="line">';
        str+='<div class="name">'+info.Name+'</div>';
        str+='<div class="value">'+info.Value+'</div>';
        str += '</div>';
    });
    $("#expand_tags").html(str);
};


function CustomerTool()
{
	if($("#customertool").length>0)
	{
		$("#customertool").show();
	}else
	{
		$("body").append('<div id="customertool" class="customertool" style="height:120px;"><ul><li id="movetohighsea">移到公海</li><li id="customeredit">修改客户资料</li><li id="customerdelete">删除客户信息</li></ul></div>');
		//初始化工具条
		get("movetohighsea").addEventListener("tap",function(){
			$("#customertool").hide();
        	plus.nativeUI.confirm("您确定要把客户【" + obj.find(".customername").html() + "】移到公海吗？", function(event){
				if(event.index==1)
				{
					var data = {};
			        data.id = obj.attr("id");
			        data.act = "SetHighSea_Customer";
			        data.cusname = obj.find(".customername").html();
			        data.userid=userid;
					data.comid=comid;
			        data.source=source;
			        data.sign=GetSign(data.act);
			        
					mui.getJSON(crm_domain, data, function (json) {
						plus.nativeUI.toast(json.msg); 
			            if (json.state) {
			            	CloseWindow();
			            	obj.remove();
			            }
			        });
				}
			},"提示", ["取消","确认"]); 
        });
		get("customeredit").addEventListener("tap",function(){
        	OpenWindow(3,"客户","保存",function(){
				Save_Customer();
			});
			$("#contentlist3").html(CustomerAdd_Code(obj.attr("id")));
			Init_CustomerAdd();
			$("#customertool").hide();
        });
        
        get("customerdelete").addEventListener("tap",function(){
        	$("#customertool").hide();
        	plus.nativeUI.confirm("确定要删除吗？", function(event){
				if(event.index==1)
				{
					var data = {};
				    data.act = "Delete_Customer";
				    data.ids = obj.attr("id");
				    data.userid=userid;
					data.comid=comid;
					data.source=source;
					data.sign=GetSign(data.act);
				    mui.getJSON(crm_domain, data, function(json) {
				    	plus.nativeUI.toast(json.msg);
						if(json.state)
						{
							CloseWindow();
							FindCrmReport();
							obj.remove();
						}
				    });	
				}
			},"提示", ["取消","确认"]); 
        });
	}
};

function FollowUser_Delete(o)
{
	plus.nativeUI.confirm("确定要删除吗？", function(event){
		if(event.index==1)
		{
					data = {};
		            data.id = obj.attr("id");
		            data.followuser = $(o).attr("uid");
		            data.handle = "delete";
		            data.userid=userid;
					data.comid=comid;
					data.source=source;
		            data.act = "FollowUser_Customer";
		            data.sign=GetSign(data.act);
		            mui.getJSON(crm_domain, data, function (json) {
		                if (json.state) {
		                    $(o).remove();
		                    plus.nativeUI.toast(json.msg);
		                } else {
		                    plus.nativeUI.toast(json.msg);
		                }
		            });
		}
	},"提示", ["取消","确认"]); 
};
